<template>
	<view classs="content">
		<view class="header">
			<image class="header_bg" src="https://mp-fff067d4-0ad0-46f1-8940-3076faaf2173.cdn.bspapp.com/image/static/summer.jpg" />
			<view class="userInfo" v-if="userInfo._id">
				<view class="avautar" @click="toPersonal">
					<image v-if="userInfo.avatar" class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
					<image v-if="!userInfo.avatar" class="avatar" src="https://mp-fff067d4-0ad0-46f1-8940-3076faaf2173.cdn.bspapp.com/image/static/default.png" mode="aspectFill"></image>
				</view>
				<view class="nickname" @click="toPersonal">{{ userInfo.nickName ? userInfo.nickName :'微信用户'}}</view>
				<view class="biaoshi">ID:{{userInfo._id || ""}}</view>
			</view>
			<view class="userInfo" v-else>
				<view class="avautar">
					<image class="" src="https://mp-fff067d4-0ad0-46f1-8940-3076faaf2173.cdn.bspapp.com/image/static/default.png" />
				</view>
				<view @click="toLogin" style="color:#666;font-size:30rpx;font-weight:700;line-height:60rpx;">点击登录</view>
			</view>
		</view>
		<view class="navTitle" v-if="userInfo._id">我的应用</view>
		<view class="nav" v-if="userInfo._id">
			<!-- 九宫格 -->
			<view class="navItem" v-for="(item,index) in navList" :key="index" @click="toPage(item)">
				<image class="img" :src="item.img" />
				<view class="text">{{item.txt}}</view>
			</view>
		</view>
		<view class="empty">
			<u-empty v-if="!userInfo._id" mode="order" text="请先登录"></u-empty>
		</view>
		<view class="foot" :style="{paddingBottom:safeAreaHeight + 'px'}" v-if="userInfo._id">
			<u-button shape="circle" type="primary" text="退出登录" @click="quitFn"></u-button>
		</view>
		<tabbar :current="2"></tabbar>
	</view>
</template>

<script>
	import tabbar from '@/components/tabbar/index.vue'
	import { systemInfo } from "@/mixins/system.js";
	import {
		navigateTo,
		getStorageSync,
		setStorageSync,
		clearStorageSync
	} from '@/static/utils'
	export default {
		data() {
			return {
				userInfo: {},
				navList: [],
			}
		},
		mixins:[systemInfo],
		components: {
			tabbar,
		},
    onLoad(options) {
      this.getNavList()
    },
		onShow() {
			this.userInfo = getStorageSync('userInfo') || {}
			if (this.userInfo._id) {
				this.getInfo()
			}
		},
		methods: {
      getNavList() {
				uni.request({
					url: 'https://fc-mp-fff067d4-0ad0-46f1-8940-3076faaf2173.next.bspapp.com/getNavList',
					data: {},
					success: (res) => {
						console.log(73,res);
						if (res.data.code == 200) {
							this.navList = []
							// #ifdef MP-WEIXIN
							res.data.data.forEach((val,idx)=>{
								if (val.type!='h5' && val.show) {
									this.navList.push(val)
								}
							})
							// #endif
							// #ifdef H5
							res.data.data.forEach((val,idx)=>{
								if (val.show) {
									this.navList.push(val)
								}
							})
							// #endif
						}
					}
				})
			},
  		quitFn(){
				this.userInfo = {}
				clearStorageSync()
			},
			toPage(item) {
				console.log(item);
				if(item.id==1 && this.userInfo._id!="67a2dacb286f7c0f8c9468af"){
					uni.showToast({
						icon: 'none',
						title: '暂无权限！'
					});
					return
				}
				// if (item.id==6) {
				// 	window.location.href= "https://tangcuyuhouse.gitee.io/boke/"
				// }else if (item.id==7) {
				// 	uni.request({
				// 		url: 'https://dayu.qqsuu.cn/moyuribao/apis.php?type=json',
				// 		data: {},
				// 		success: (res) => {
				// 			console.log(res);
				// 			if (res.data.code == 200) {
				// 			  uni.previewImage({
				// 			  	urls:[res.data.data],
				// 			  })
				// 			}
				// 		}
				// 	})
				// }else{
				// 	navigateTo(item.path)
				// }
				navigateTo(item.path)
			},
			getInfo() {
				const data = {
					_id: getStorageSync('userInfo')._id || "",
				}
				uni.request({
					url: 'https://fc-mp-fff067d4-0ad0-46f1-8940-3076faaf2173.next.bspapp.com/getUser',
					data: data,
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							this.userInfo = res.data.userInfo
							setStorageSync('userInfo', this.userInfo)
						}
					}
				})
			},
			toPersonal() {
				navigateTo("personal/personal")
			},
			toLogin() {
				navigateTo("login/login")
			}
		}
	}
</script>

<style lang="less" scoped>
	
	.header {
		position: relative;
		height: 530rpx;

		.header_bg {
			width: 100%;
			height: 530rpx;
		}

		.userInfo {
			z-index: 1;
			position: absolute;
			top: 0;
			left: 50%;
			transform: translateX(-50%);
			padding: 30rpx;
			color: #fff;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-top: 100rpx;

			.avautar {
				width: 150rpx;
				height: 150rpx;
				border-radius: 50%;
				padding: 10rpx;
				background: rgba(229, 234, 238, 0.7);

				image {
					width: 100%;
					height: 100%;
					/* margin: 10rpx; */
					border-radius: 50%;
				}
			}
		}
	}

	.nickname {
		line-height: 60rpx;
		font-weight: 700;
		color: #333;
	}

	.biaoshi {
		line-height: 30rpx;
		font-size: 24rpx;
		color: #333;
	}
  .empty{
		padding-top: 200rpx;
	}
	.nav {
		background-color: #fff;
		margin-bottom: 20rpx;
		display: flex;
		flex-direction: initial;
		align-items: center;
		justify-content: flex-start;
		flex-wrap: wrap;
	}
	.foot{
		width: 100%;
		position: fixed;
		bottom: 110rpx;
		left: 0;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
	}

	.navTitle {
		/* background-color: #fff; */
		background: linear-gradient(#e5eefd, #ffffff);
		text-align: left;
		padding: 15rpx 28rpx;
		font-size: 26rpx;
		border-bottom: 1px solid #eee;
		font-weight: 700;
	}

	.nav .navItem {
		padding: 20rpx 0;
		width: 25%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
		.img {
			width: 75rpx;
			height: 75rpx;
		}
		.text {
			font-size: 24rpx;
			color: #333;
			padding: 15rpx 15rpx 0;
		}
	}
</style>